import { config } from 'dotenv';
import { DataSource } from 'typeorm';
import { dataSourceOptions } from '../../config/data-source';
import { runSeeds } from './index';

// 加载环境变量
config();

async function main() {
  console.log('正在连接数据库...');
  
  const dataSource = new DataSource(dataSourceOptions);
  await dataSource.initialize();
  
  try {
    await runSeeds(dataSource);
  } catch (error) {
    console.error('数据初始化失败:', error);
    process.exit(1);
  } finally {
    await dataSource.destroy();
  }
  
  process.exit(0);
}

main(); 